<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>js练习-函数基础使用</title>
  </head>
  <body>
    <div id="errors"></div>
    <form action="http://www.bigabc.top/" onsubmit="return onSubmit()">
      手机号：<input type="text" name="mobile" />
      <button>提交</button>
    </form>
    <script>
      function onSubmit() {
        // let input = document.querySelector('input[type="text"]')
        // let input = document.querySelector('[name="mobile"]')
        let input = document.querySelector('input').value.trim()
        if (input == false) {
          message('手机号不能为空')
        } else {
          console.log('下一步')
        }
        return false
      }

      function message(message) {
        let container = document.querySelector('#errors')
        container.innerHTML = message
      }
    </script>
  </body>
</html>
